package com.zhang.test;

import com.zhang.comm.utils.StringUtils;
import com.zhang.bingmei_incomeexpenditure.entity.commom.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zsj
 * @description
 * @createDate 2025/11/21 14:30
 * @Entity com.zhang.test.entity.
 */
@RestController
@RequestMapping("/ip")
@CrossOrigin(origins = "*")
@Slf4j
public class GetIPController {

    @PostMapping("/getIp")
    public R<String> uploadPic(HttpServletRequest request) {
        String requestIp = StringUtils.getIp(request);
        String address = StringUtils.getLoginAddress(requestIp);

        if (StringUtils.isBlank(address)) {
            address = "未知地址（本地回环地址或无定位信息）";
        }

        String result = String.format("requestIp: %s, Address: %s", requestIp, address);
        log.debug("IP查询结果：{}", result);
        return R.ok("IP查询成功", result);
    }
}
